$(document).ready(function(){
	$("#accountz").click(function(){
		$("#account-list").slideToggle();
	});
	$(".loader").hide();
	$("#add-recipients-wrap").hide();
	$('.error-r').hide();
	$('.notice').hide();
	$("#recipients-btn").click(function(){
		$("#add-recipients-wrap").fadeIn("slow");
	});
	$("#m-close").click(function(){
		$("#add-messages-wrap").fadeOut("slow");
	});
	$("#r-close").click(function(){
		$("#add-recipients-wrap").fadeOut("slow");
	});
	$('#totype-list-recipients').hide();
	$("#con-receptients input").focus(function(){ $(this).val('');
		switch($(this).attr('id')){
			case 'add-recep-fname': $(this).focusout(function(){
				if($(this).val()=='') $(this).val('First Name');
			}); break;
			case 'add-recep-lname': $(this).focusout(function(){
				if($(this).val()=='') $(this).val('Last Name');
			}); break;
			case 'add-recep-mname': $(this).focusout(function(){
				if($(this).val()=='') $(this).val('Middle Name');
			}); break;
			case 'add-recep-address':     $(this).focusout(function(){
				if($(this).val()=='') $(this).val('Address');
			}); break;
			case 'add-recep-contact':  $(this).focusout(function(){
				if($(this).val()=='') $(this).val('Contact Address');
			}); break;
			case 'add-recep-phone':  $(this).focusout(function(){
				if($(this).val()=='') $(this).val('Phone');
			}); break;
			case 'add-recep-email':  $(this).focusout(function(){
				if($(this).val()=='') $(this).val('Email');
			}); break;
		}//end switch
	});
	$("#recep-cancel").click(function(){
		var base = $('#hidden2base').val();
		location.href=base+"recipients"
	});
	$("#con-recipients input[type=text]").live('focus',function(){ //$(this).val('');
		switch($(this).attr('id')){
			case 'add-recep-fname': 
				($(this).val() == 'First Name')? $(this).val(''):'';
				$(this).focusout(function(){
				if($(this).val()=='') $(this).val('First Name');
				
			}); break;
			case 'add-recep-lname': 
				($(this).val() == 'Last Name')? $(this).val(''):'';
				$(this).focusout(function(){
				if($(this).val()=='') $(this).val('Last Name');
			}); break;
			case 'add-recep-mname': 
				($(this).val() == 'Middle Name')? $(this).val(''):'';
				$(this).focusout(function(){
				if($(this).val()=='') $(this).val('Middle Name');
			}); break;
			case 'add-recep-address':     
				($(this).val() == 'Address')? $(this).val(''):'';
				$(this).focusout(function(){
				if($(this).val()=='') $(this).val('Address');
			}); break;
			case 'add-recep-state':  
				($(this).val() == 'State')? $(this).val(''):'';
				$(this).focusout(function(){
				if($(this).val()=='') $(this).val('State');
			}); break;
			case 'add-recep-city':     
				($(this).val() == 'City')? $(this).val(''):'';
				$(this).focusout(function(){
				if($(this).val()=='') $(this).val('City');
			}); break;
			case 'add-recep-zip':     
				($(this).val() == 'Zip')? $(this).val(''):'';
				$(this).focusout(function(){
				if($(this).val()=='') $(this).val('Zip');
			}); break;
			case 'add-recep-contact':  
				($(this).val() == 'Contact Address')? $(this).val(''):'';
				$(this).focusout(function(){
				if($(this).val()=='') $(this).val('Contact Address');
			}); break;
			case 'add-recep-phone': 
				$(this).focusout(function(){
				($(this).val() == 'Phone')? $(this).val(''):'';
				if($(this).val()=='') $(this).val('Phone');
			}); break;
			case 'add-recep-email':  
				($(this).val() == 'Email')? $(this).val(''):'';
				$(this).focusout(function(){
				if($(this).val()=='') $(this).val('Email');
			}); break;
		}//end switch
	});
	$("#r-search").click(function(){
		if($(this).val() == 'Type Here...'){$(this).val("");}
	});
	$("#r-search").blur(function(){
		if($(this).val() == ''){$(this).val("Type Here...");}
	});
	//$("#add_recipients_frm").submit(function(){
	$("#recep-submit").click(function(){
		$('.error-r').html('');
		var fname = $('#add-recep-fname').val();
		var lname = $('#add-recep-lname').val();
		var mname = $('#add-recep-mname').val();
		var phone = $('#add-recep-phone').val();
		var email = $('#add-recep-email').val();
		var emailReg = /^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/;
		var error = 0,err_email = '',msg='',email_exist;
		var base = $('#hidden2base').val();
		if(fname == "First Name"){
			error++;
			$('#add-recep-fname').css("border","1px solid #FF0000");
		}else{
			$('#add-recep-fname').css("border","1px solid #707070");
		}//end if
		if(lname == "Last Name"){
			error++;
			$('#add-recep-lname').css("border","1px solid #FF0000");
		}else{
			$('#add-recep-lname').css("border","1px solid #707070");
		}//end if
		if(mname == "Middle Name"){
			error++;
			$('#add-recep-mname').css("border","1px solid #FF0000");
		}else{
			$('#add-recep-mname').css("border","1px solid #707070");
		}//end if
		if(phone == "Phone"){
			error++;
			$('#add-recep-phone').css("border","1px solid #FF0000");
		}else{
			$('#add-recep-phone').css("border","1px solid #707070");
		}//end if
		if(email == "Email"){
			error++;
			$('#add-recep-email').css("border","1px solid #FF0000");
		}else if(!(emailReg.test(email)) ){
			err_email = "Invalid email format."
			$('#add-recep-email').css("border","1px solid #FF0000");
		}else{
			$.ajax({
				url:base+'recipients/check_email_exist',
				type:'post',
				data:'email='+email,
				success:function(data){
					if(error == 0 && err_email == '' && data == '0'){
						$('#add-recep-email').css("border","1px solid #707070");
						var form_data = $('#add_receptients_frm').serialize();
						$.ajax({
							url: base+'recipients/create_recipients',
							data: form_data,
							type : 'POST',
							beforeSend: function(){
								$(".error-r").hide();
								$(".loader").show();
							},
							success: function(data){
								$('.loader').fadeOut(3000,function(){
									$('.error-r').html("Successfully saved recipient.").fadeIn(500).delay(4000).fadeOut(500, function(){
										$('#add-recep-address').css({'margin-bottom':'0'});
										$("#add-receptients-wrap").delay(1000).fadeOut("slow");
										/* for recipients side bar counter update*/
										var r_counter = parseInt($('#inp_rcounter').val());
										var ctr_min = r_counter + 1;
										$('#inp_rcounter').val(ctr_min);
										$('#rep_counter').html($('#inp_rcounter').val());
										/* end of recipient side bar counter update */
										clear_add_rep_fields();
									});
								});
							},
							complete: function(){
								window.location = base+'recipients/';
							}
						});
					}else{
						$('#add-recep-email').css("border","1px solid #FF0000");
						if($('.error-r').html() == ''){
							$('.error-r').html('Recipient\'s email already exist.');
						}else{
							$('.error-r').append('Recipient\'s email already exist.');
						}//end if
						$('.error-r').show();
					}//end if
				}
			});
		}//end if
		$('#con-receptients input[type="text"]').css({'margin-bottom':'15px','height':'30px'})
		$('#add-recep-address').css({'margin-bottom':'0'});
		if(error > 0){msg = 'Please fill up all required fields.<br/>'}
		$('.error-r').html(msg+err_email);
		$('.error-r').show();
	});
	$('#recep-edit').click(function(){
		var fname = $('#add-recep-fname').val();
		var lname = $('#add-recep-lname').val();
		var mname = $('#add-recep-mname').val();
		var phone = $('#add-recep-phone').val();
		var email = $('#add-recep-email').val();
		var emailReg = /^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/;
		var error = 0,err_email = '',msg='',email_exist;
		var path = $('#path').val();
		if(fname == "First Name"){
			error++;
			$('#add-recep-fname').css("border","1px solid #FF0000");
		}else{
			$('#add-recep-fname').css("border","1px solid #707070");
		}//end if
		if(lname == "Last Name"){
			error++;
			$('#add-recep-lname').css("border","1px solid #FF0000");
		}else{
			$('#add-recep-lname').css("border","1px solid #707070");
		}//end if
		if(mname == "Middle Name"){
			error++;
			$('#add-recep-mname').css("border","1px solid #FF0000");
		}else{
			$('#add-recep-mname').css("border","1px solid #707070");
		}//end if
		if(phone == "Phone"){
			error++;
			$('#add-recep-phone').css("border","1px solid #FF0000");
		}else{
			$('#add-recep-phone').css("border","1px solid #707070");
		}//end if
		if(email == "Email"){
			error++;
			$('#add-recep-email').css("border","1px solid #FF0000");
		}else if(!(emailReg.test(email)) ){
			err_email = "Invalid email format."
			$('#add-recep-email').css("border","1px solid #FF0000");
		}else{
			$('#add-recep-email').css("border","1px solid #707070");
		}//end if
		if(error == 0 && err_email == ''){
			var path = $('#path').val();
			var form_data = $('#edit_receptients_frm').serialize();
			var html = '';
			$.ajax({
				url:path+'recipients/update_recipient',
				type:'post',
				data:form_data,
				success:function(data){
					if(data == '1'){
						html += '<label>'+$('#add-recep-fname').val()+'&nbsp;'+$('#add-recep-lname').val()+'</label>';
						html += '<p>'+$('#add-recep-address').val()+'</p>';
						html += '<p>'+$('#add-recep-phone').val()+'</p>';
						html += '<div id = "recipient-control">';
							html += '<a href = "javascript:void(0);" onclick="edit_recipient(\''+$('#edit-recep-id').val()+'\')">';
							html += '<img src = "'+path+'assets/images/edit-btn.png" alt = "" /></a>&nbsp;&nbsp;&nbsp;';
							html += '<a href = "javascript:void(0)" onclick="deleteRecipient(\''+$('#edit-recep-id').val()+'\')">';
							html += '<img src = "'+path+'assets/images/trash-can.png" alt = "" /></a>&nbsp;&nbsp;|&nbsp;&nbsp;&nbsp;';
							if($("input[name=is_executor]").is(":checked")){
								html += '<img src="'+path+'assets/images/check.png" alt="An Executor" title="An Executor" />';
							}else{
								html += '<img src="'+path+'assets/images/wrong.png" alt="Not an Executor" title="Not an Executor" />';
							}
						html += '</div>';
						$('#recipient-context_'+$('#edit-recep-id').val()).html(html);
						$('.error-r').html('Successfully updated '+$('#add-recep-fname').val()+' info').fadeIn(500).delay(4000).fadeOut(500, function(){
							$('#ad_wrap').fadeOut(2000);
						});
					}

				}
			});
		}else{
			$('#con-receptients input[type="text"]').css({'margin-bottom':'15px','height':'30px'})
			$('#add-recep-address').css({'margin-bottom':'0'});
			if(error > 0){msg = 'Please fill up all fields.<br/>'}
			$('.error-r').html(msg+err_email);
			$('.error-r').show();
		}//end if
		return false;
	});
	$('#recep-edit-cancel').click(function(){
		$('#ad_wrap').hide();
		return false;
	});
	$("#con-receptients input").live('focus',function(){
		switch($(this).attr('id')){
			case 'add-recep-fname': $(this).focusout(function(){
				if($(this).val()=='') $(this).val('First Name');
			}); break;
			case 'add-recep-lname': $(this).focusout(function(){
				if($(this).val()=='') $(this).val('Last Name');
			}); break;
			case 'add-recep-mname': $(this).focusout(function(){
				if($(this).val()=='') $(this).val('Middle Name');
			}); break;
			case 'add-recep-address':     $(this).focusout(function(){
				if($(this).val()=='') $(this).val('Address');
			}); break;
			case 'add-recep-contact':  $(this).focusout(function(){
				if($(this).val()=='') $(this).val('Contact Address');
			}); break;
		}//end switch
	});
	$('#recipient-searchsubmit').click(function(){
		var path = $('#path').val();
		var form_data = $('#frm_rec_search').serialize();
		if($('#r-search').val() != '' && $('#r-search').val() != 'Type Here...'){
			$.ajax({
				url:path+'recipients',
				type:'post',
				data:form_data,
				beforeSend: function(){
					$(".loader").show();
				},
				success:function(data){
					$(".loader").fadeOut(function(){
						$('#div_results').html(data).slideDown(2000);
					});
				}
			});
		}//end if
		return false;
	});
	$('#btn-addpost').click(function(){
		$('#add_remwall').fadeIn(1000);
	});
	$('#rem-cancel').click(function(){
		$('#add_remwall').fadeOut(1000,function(){
			$('#cancel_flower').trigger('click');
			$('.flower_gallery_wrapper').hide();
			$('.error-r').html('');
			$('.error-r').hide();
			$('#con-recipients select,#con-recipients input[type="text"],#con-recipients textarea').css("border","1px solid #707070");
		});
	});
	$('#sel_birthday_month,#sel_death_month').change(function(){
		var base = $('#base_path').val();
		var id = $(this).attr('id');
		$.ajax({
			url:base+'profile/get_days_per_month',
			type:'post',
			data:'month='+$(this).val()+'&id='+id,
			success:function(data){
				if(id == 'sel_birthday_month'){
					$('#sel_birthday_day').replaceWith(data);
				}else{
					$('#sel_death_day').replaceWith(data);
				}
			}
		});
	});
	$('#add-remwall-msg').focus(function(){
		$(this).val('');
		$(this).focusout(function(){
			if($(this).val()=='') $(this).val('Message');
		});
	});
	$('#add-remwall-name').focus(function(){
		($(this).val() == 'Name of the Person')? $(this).val(''):'';
		$(this).focusout(function(){
			if($(this).val()=='') $(this).val('Name of the Person');
		});
	});
	$('#add_flower').click(function(){
		var id = $(this).attr('id');
		$('.flower_gallery_wrapper').slideDown(500,function(){
			$('#'+id).attr('id','cancel_flower');
			$('#cancel_flower .fontbb002a').html('Cancel');
			$('.slidedown_icon').replaceWith('<div class="slideup_icon fleft"></div>');
		});
	});
	$('#cancel_flower').live('click',function(){
		var id = $(this).attr('id');
		$('.flower_gallery_wrapper').slideUp(500,function(){
			$('#file_name').val('');
			$('#flower_list li a img').css({'border':'4px solid #fff'});
			$('#'+id).attr('id','add_flower');
			$('#add_flower .fontbb002a').html('Add');
			$('.slideup_icon').replaceWith('<div class="slidedown_icon fleft"></div>');
		});
	});
	$('#flower_list li a').click(function(){
		$('#flower_list li a img').css({'border':'4px solid #fff'});
		$(this).children().css({'border':'4px solid #bf002b'});
		$('#file_name').val($(this).children().attr('src'));
	});
	$('#remem-submit').click(function(){
		var base = $('#base_path').val();
		var form_data = $('#add_remwall_frm').serialize();
		var error = 0;
		if($('#add-remwall-name').val() == 'Name of the Person'){
			error++;
			$('#add-remwall-name').css("border","1px solid #FF0000");
		}else{
			$('#add-remwall-name').css("border","1px solid #707070");
		}//end if
		if($('#add-remwall-msg').val() == 'Message'){
			error++;
			$('#add-remwall-msg').css("border","1px solid #FF0000");
		}else{
			$('#add-remwall-msg').css("border","1px solid #707070");
		}//end if
		if(error == 0){
			$.ajax({
				url:base+'profile/save_remembrance_wall',
				type:'post',
				data:form_data,
				success:function(data){
					if(data != '0'){
						$('.error-r').html('Successfully saved post.').fadeIn(2000,function(){
							$('#rem-cancel').trigger('click');
							$('.rem_wrapper').prepend(data);
						});
					}//end if
				}
			});
		}else{
			$('.error-r').html('Please fill up form correctly.').show();
		}//end if
	});
	$('#sel_birthday_year').change(function(){
		var base = $('#base_path').val();
		var currentTime = new Date();
		var c_year = currentTime.getFullYear();//current year
		var html = '';
		html += '<select name="sel_death_year" id="sel_death_year">';
		html += '<option value="">Year</option>';
		//"edit_recipient(\''+$('#edit-recep-id').val()+'\')"
		for(year=c_year;year>=$(this).val();year--){
			html += '<option value="'+year+'">'+year+'</option>';
		}//end for
		html += '</select>';
		$('#sel_death_year').replaceWith(html);
	});

	$('#fc_click_here').click(function(){
		if($('#fc_rwrapper').is(':visible')){
			$(this).html('<div id="fc_arr_down" class="fleft"></div><div class="fleft">Click Here to View</div>');
			$('#fc_rwrapper').slideUp(500);
		}else{
			$(this).html('<div id="fc_arr_up" class="fleft"></div><div class="fleft">Click Here to Hide</div>');
			$('#fc_rwrapper').slideDown(500);
		}//end if
	});
	$('.fc_r_pass').keypress(function(event){
		var keycode = (event.keyCode ? event.keyCode : event.which);
		if(keycode == '13'){
			$(this).parent().children('.fc_passwordok').trigger('click');
			return false;
		}//end if
	});
	//executor slidedown/slideup sidebar
	$('#fc_exec_click_here').click(function(){
		if($('#fc_exec_rwrapper').is(':visible')){
			$(this).html('<div id="fc_arr_down" class="fleft"></div><div class="fleft">Click Here to View</div>');
			$('#fc_exec_rwrapper').slideUp(500);
		}else{
			$(this).html('<div id="fc_arr_up" class="fleft"></div><div class="fleft">Click Here to Hide</div>');
			$('#fc_exec_rwrapper').slideDown(500);
		}//end if
	});

	$('.fc_passwordok,.fc_exec_passwordok').click(function(){
		var pointer = $(this);
		var baseurl = $('#fc_base').val();
		var indicator = $(this).parent().children('.fc_indicator.').val();
		if(indicator=='1'){
			var pass = $(this).parent().children('.fc_r_pass_exec').val();
			var userid = $(this).parent().children('.fc_r_userid_exec').val();
			var executor = '1';
		}else{
			var pass = $(this).parent().children('.fc_r_pass').val();
			var userid = $(this).parent().children('.fc_r_userid').val();
			executor = '';
		}//end if
		$.ajax({
			url:baseurl+'profile/check_user_password',
			type:'post',
			data:'password='+pass+'&userid='+userid+'&executor='+executor,
			success:function(data){
				if(data == 'true'){
					if(executor=='1'){
						$('.wrong').hide();
						pointer.parent().parent().parent().children('.notify_button').show();
						return false;
					}else{
						pointer.parent().parent().parent().children('.msg_content').html('<div class="correct">Authentication success</div>');
					}//end if
					location.href=baseurl+'profile/eulogy/'+userid;
				}else{
					pointer.parent().parent().parent().children('.msg_content').html('<div class="wrong">Invalid</div>');
					return false;
				}//end if
			}
		});

	});

	//for notify button
	$(".notify_btn").on('click',function(){
		var baseUrl = $('#fc_base').val();
		var userid =$(this).parent().parent().find('.fc_r_userid_exec').val();

		$.ajax({
			url: baseUrl+'recipients/notification',
			type:'POST',
			data:'userId='+userid,
			success:function(response){
		//alert(response);return false;
				$('#main-content-wrap').html(response);
			}

		});//end ajax
	 return false;
	});

	//for upgrade button
	$(".upgrade-btn").click(function(){
		var path = $("#base_path_u").html();
		$.ajax({
			url:path+'register/upgrade',
			success:function(response){
				$("#main-content-wrapper").html(response);
			}
		});//end ajax
		return false;
	});
	$('#frm_edit_profile').submit(function(){
		var error = 0;
		$('#frm_edit_profile input[type="text"]').each(function(){
			if($.trim($(this).val()) == "" && $(this).attr('id') != 'ep-birthday'){
				$(this).css({"border":"1px solid #FF0000"});
				error++;
			}else{
				$(this).css({"border":"1px solid #707070"});
			}//end if
		});
		if(error > 0){
			$('#edit_profile_wrapper .error_msg').html('Please specify first name/middle name/last name.').fadeIn(500);
			return false;
		}
	});
	$('#ep-cancel').click(function(){location.href=$.trim($('#base_path_u').html())+"profile";});
	/* contact us */
	$("#contact-wrap input, #contact-wrap textarea").focus(function(){ $(this).val('');
		switch($(this).attr('id')){
			case 'contact_name': $(this).focusout(function(){
				if($(this).val()=='') $(this).val('Your Name');
			}); break;
			case 'contact_email': $(this).focusout(function(){
				if($(this).val()=='') $(this).val('Your Email');
			}); break;
			case 'contact_subject': $(this).focusout(function(){
				if($(this).val()=='') $(this).val('Your Subject');
			}); break;
			case 'contact_message': $(this).focusout(function(){
				if($(this).val()=='') $(this).val('Your Message');
			}); break;
		}//end switch
	});
	$('#contact-submit').click(function(){
		var contact_name = $('#contact_name').attr("value");
		var contact_email = $('#contact_email').attr("value");
		var contact_subject = $('#contact_subject').attr("value");
		var contact_message = $('#contact_message').attr("value");
		var emailReg = /^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/;
		var captcha = $('#captcha').attr("value");
		var error = 0;
		if(contact_name == "Your Name"){
			error++;
			$('#contact_name').css({"border":"1px solid #FF0000"});
		}else{
			$('#contact_name').css({"border":"1px solid #707070"});
		}//end if
		if(contact_email == "Your Email"){
			error++;
			$('#contact_email').css({"border":"1px solid #FF0000"});
		}else if(!(emailReg.test(contact_email)) ){
			error++;
			$('#contact_email').css({"border":"1px solid #FF0000"});
		}else{
			$('#contact_email').css({"border":"1px solid #707070"});
		}//end if
		if(contact_subject == "Your Subject"){
			error++;
			$('#contact_subject').css({"border":"1px solid #FF0000"});
		}else{
			$('#contact_subject').css({"border":"1px solid #707070"});
		}//end if
		if(contact_message == "Your Message"){
			error++;
			$('#contact_message').css({"border":"1px solid #FF0000"});
		}else{
			$('#contact_message').css({"border":"1px solid #707070"});
		}//end if
		if(captcha == "" && error > 0){
			error++;
			$('#captcha').css({"border":"1px solid #FF0000"});
			$('.error').html("Please fill up form correctly.").fadeIn(1000);
		}else{
			var $captcha = $('#captcha').val();
			var path = $('#hidden-captcha').attr("value");
			$.ajax({
				url:path,
				type:'post',
				data:'captcha='+$captcha,
				success:function(data) {
					if(data=='same' && error==0){
						$('#captcha').css({"border":"1px solid #707070"});
						$('.error').hide();
						$('#contact-form').submit();
					}else{
						(data=='same')? $('#captcha').css({"border":"1px solid #707070"}):$('#captcha').css({"border":"1px solid #FF0000"});
						$('.error').html("Please fill up form correctly.").fadeIn(1000);
					}//end if
				}
			});
		}//end if
	});
	/* end of contact us */
});

function clear_add_rep_fields(){
	$('#add-recep-fname').val('First Name');
	$('#add-recep-lname').val('Last Name');
	$('#add-recep-mname').val('Middle Name');
	$('#add-recep-address').val('Address');
	$('#add-recep-contact').val('Contact Address');
	$('#add-recep-phone').val('Phone');
	$('#add-recep-email').val('Email');
	$('.error-r').html('');
	$('.error-r').hide('');
	$('#con-receptients input[type="text"]').css({'margin-bottom':'19px','height':'35px','border':''})
	$('#add-recep-address').css({'margin-bottom':'0'});
}//end fct
function deleteRecipient(id){
	var path = $('#path').val();
	$del = confirm("Do you really want to delete this recipient?");
	if($del){
		//var dataString = 'RecipientID=' +id + '&action=deleterecipient';
		var notice = 'Successfully deleted recipient.';
		$.ajax({
			url: path+'recipients/delete_recipients',
			type: 'POST',
			data:'rec_id='+id,
			beforeSend: function(){
			  // Handle the beforeSend event
			 },
			success: function(data) {
				$('.notice').html(notice);
				$('.notice').fadeIn(2000,function(){
					$('#recipient-context_'+id).slideUp(2000,function(){
						/* for recipients side bar counter update*/
							var r_counter = parseInt($('#inp_rcounter').val());
							var ctr_min = r_counter - 1;
							$('#inp_rcounter').val(ctr_min);
							$('#rep_counter').html($('#inp_rcounter').val());
							/* end of recipient side bar counter update */
						$('.notice').fadeOut(500);
						$('#recipient-context_'+id).remove();
					});
				});
			},
			complete: function(){
				// Handle the complete event
			}
		});
		return false;

	}//end if
}//end fct

function edit_recipient(id){
	var path = $('#path').val();
	$.ajax({
		url:path+'recipients/edit_recipient',
		type:'post',
		data:'rec_id='+id,
		success:function(data){
			$('#rec_edit_fields').html(data);
			$('#ad_wrap').show();
		}
	});
}//end fct

function DeleteMessage(id){
	if( confirm("Do you really want to delete this message?") ){
		var baseurl = $('#baseurl').val()
		var url = baseurl+'messages/delete/'+id
		$.ajax({
			url: url,
			type: 'POST',
			data: {},
			success: function(data) {
				$('#mssg'+id).remove();
			}
		});
	}//end if
	return false;
}//end fct

